package com.tlgen.util;

import com.tlgen.annation.FruitColor;
import com.tlgen.annation.FruitName;
import com.tlgen.annation.FruitProvider;

import java.lang.reflect.Field;

public class FruitInfoUtil {

    public static void getFruitInfo(Class<?> clazz) {

        String strFruitName = "水果名称: ";
        String strFruitColor = "水果颜色: ";
        String strFruitProvide = "供应商消息: ";

        Field[] fields = clazz.getDeclaredFields();

        for (Field field : fields) {
            if (field.isAnnotationPresent(FruitName.class)) {
                FruitName fruitName = field.getAnnotation(FruitName.class);
                strFruitName = strFruitName + fruitName.value();
                System.out.println(strFruitName);
            }

            if (field.isAnnotationPresent(FruitColor.class)) {
                FruitColor fruitColor = field.getAnnotation(FruitColor.class);
                strFruitColor = strFruitColor + fruitColor.fruitColor().toString();
                System.out.println(strFruitColor);
            }

            if (field.isAnnotationPresent(FruitProvider.class)) {
                FruitProvider fruitProvider = field.getAnnotation(FruitProvider.class);
                strFruitProvide = strFruitProvide + "{\n供应商编号: " + fruitProvider.id() + "\n供应商名称: "
                        + fruitProvider.name() + "\n供应商地址: " + fruitProvider.address() + "\n}";
                System.out.println(strFruitProvide);
            }
        }
    }
}
